<?php

namespace app\admin\controller;

use app\common\model\Pray as PrayModel;
/**
 * 祈福忏悔控制器
 * Class Pratice
 * @package app\admin\controller
 */
class Pray extends Base
{
    /**
     * [getIndex  获取修行设置]
     * @param 1祈福 2忏悔
     * @return json
     * @author [C。]
     */
    public function getIndex()
    {
        $param = input('param.');
        $model = new PrayModel;
        $this->getPageAndSize($param);
        $map = [];
        $user = $this->user;
        try{
            $map['type'] = $param['type'];
            $field = 'p.id,am.tel,am.username,am.sex,p.fo_name,p.name,p.content,p.create_time';
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getList($map,$this->from, $this->size,$field);
            foreach ($lists as &$v){
                $v['content'] = urldecode($v['content']);
            }
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        if($param['type'] == 1){
            $name = '祈福';
        }elseif($param['type'] == 2){
            $name = '忏悔';
        }
        writelog('查看'.$name.'列表',1,$user);
        return admin_json(1,'获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}